package huawei.js2025;

import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

/**
 * Excel单元格数值统计
 */
public class Question24 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<Integer> op = Arrays.stream(sc.nextLine().trim().split(" ")).map(Integer::parseInt).collect(Collectors.toList());
        String[][] excel = new String[op.get(0)][op.get(1)];

        for (int i = 0; i < op.get(0); i++) {
            String[] cells = sc.nextLine().trim().split(" ");
            for (int j = 0; j < op.get(1); j++) {
                excel[i][j] = cells[j].trim();
            }
        }

        boolean[][] is = new boolean[op.get(0)][op.get(1)];
        int[][] excelVals = new int[op.get(0)][op.get(1)];
        for (int i = 0; i < op.get(0); i++) {
            for (int j = 0; j < op.get(1); j++) {
                compute(excel,excelVals, i, j);
            }
        }

        int sum = 0;
        for (int i = 0; i < op.get(0); i++) {
            for (int j = 0; j < op.get(1); j++) {
                sum += excelVals[i][j];
            }
        }

        System.out.println(sum);
    }

    private static int compute(String[][] excel, int[][] excelVals, int i, int j) {
        String cell = excel[i][j];
        if (cell.charAt(0) == '=') {
            cell = cell.substring(1);
            for (int k = 0; k < cell.length(); k++) {
                if (cell.charAt(k) == '+' || cell.charAt(k) == '-') {
                    char op = cell.charAt(k); // 操作

                    String op1 = cell.substring(0, k);
                    String op2 = cell.substring(k + 1);

                    int val1, val2;
                    if (op1.charAt(0) >= 'A' && op1.charAt(0) <= 'Z') {
                        int col = op1.charAt(0) - 'A';
                        int row = Integer.parseInt(op1.substring(1)) - 1;
                        if (row < i || (i == row && col < j)) {
                            val1 = excelVals[row][col];
                        } else {
                            val1 = compute(excel, excelVals, row, col);
                        }
                    } else {
                        val1 = Integer.parseInt(op1);
                    }

                    if (op2.charAt(0) >= 'A' && op2.charAt(0) <= 'Z') {
                        int col = op2.charAt(0) - 'A';
                        int row = Integer.parseInt(op2.substring(1)) - 1;
                        if (row < i || (i == row && col < j)) {
                            val2 = excelVals[row][col];
                        } else {
                            val2 = compute(excel, excelVals, row, col);
                        }
                    } else {
                        val2 = Integer.parseInt(op2);
                    }

                    if (op == '-') {
                        excelVals[i][j] = val1 - val2;
                    } else {
                        excelVals[i][j] = val1 + val2;
                    }

                    return excelVals[i][j];
                }
            }
            return -1;
        } else {
            excelVals[i][j] = Integer.parseInt(cell);
            return excelVals[i][j];
        }
    }
}
